//
//  DrawView.m
//  30203笑脸
//
//  Created by student on 16/4/6.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "DrawView.h"

@implementation DrawView

-(void)setN:(int)n
{
    _n = n;
    [self setNeedsDisplay];
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
    CGPoint center = CGPointMake(rect.size.width/2, rect.size.height/2);//中心点
    CGFloat radius = rect.size.width / 2;  //半径
    CGFloat startAngle = 0;//起始位置
    CGFloat endAngle = M_PI * 2;
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:center];
    [path addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
    [path closePath];
    [[UIColor blueColor]setStroke];
    path.lineWidth = 5;
    [path stroke];
    
    CGPoint center2 = CGPointMake(rect.size.width/4, rect.size.height/4);//中心点
    CGFloat radius2 = 30;  //半径
    
    UIBezierPath *path2 = [UIBezierPath bezierPath];
    [path2 moveToPoint:center2];
    [path2 addArcWithCenter:center2 radius:radius2 startAngle:startAngle endAngle:endAngle clockwise:YES];
    [path2 closePath];
    [[UIColor blueColor]setStroke];
    path2.lineWidth = 5;
    [path2 stroke];
    
    CGPoint center3 = CGPointMake((rect.size.width/4)*3,rect.size.height/4);//中心点
    CGFloat radius3 = 30;  //半径
    
    UIBezierPath *path3 = [UIBezierPath bezierPath];
    [path3 moveToPoint:center3];
    [path3 addArcWithCenter:center3 radius:radius2 startAngle:startAngle endAngle:endAngle clockwise:YES];
    [path3 closePath];
    [[UIColor blueColor]setStroke];
    path3.lineWidth = 5;
    [path3 stroke];
    
    CGPoint center4 = CGPointMake(rect.size.width/2, rect.size.height);//中心点
    CGFloat radius4 = 100;  //半径
    CGFloat startAngle4 = -(M_PI_2)/3*5;//起始位置
    CGFloat endAngle4 = -(M_PI_2)/3;

    switch (self.n) {
        case 1:
        {
            UIBezierPath *path = [UIBezierPath bezierPath];
            [path addArcWithCenter:center4 radius:radius4 startAngle:startAngle4 endAngle:endAngle4 clockwise:YES];
            [path closePath];
            [[UIColor blueColor]setStroke];
            path.lineWidth = 5;
            [path stroke];
        }
            break;
        case 2:
        {
            CGPoint center=CGPointMake(rect.size.width/2, rect.size.height);
            CGContextRef ctx=UIGraphicsGetCurrentContext();
            //设置起点
            CGContextMoveToPoint(ctx, center.x-100, center.y-100);
            //设置终点
            CGContextAddLineToPoint(ctx,center.x+100, center.y-100);
            CGContextSetLineWidth(ctx, 10);
            //4.绘制出来（渲染）
            CGContextStrokePath(ctx);
        }
            break;
        case 3:
        {
            CGPoint center=CGPointMake(rect.size.width/2, rect.size.height-150);
            CGFloat radius=100;
            CGFloat startAngle=(M_PI_2)/3;
            CGFloat endAngle=(M_PI_2)/3*5;
            UIBezierPath *path4=[UIBezierPath bezierPath];
            [path4 addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
            [[UIColor yellowColor]setStroke];
            path4.lineWidth=10;
            [path4 stroke];
        }
            break;
            
        default:
            break;
    }


}

//嘴
-(void)drawGraphics
{
    }


@end
